/*
 * Copyright 2008 Jens Meiss
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package mtt.rms.dataObjects;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import hmvc.j2me.framework.rms.IRMSSerializeable;

/**
 * 
 * 
 * @author jens.meiss
 */
public class Event implements IRMSSerializeable {

	/**
	 * Definiert den Index für den Typ "Vorlesung Obligatorisch"
	 */
	public static final int TYPE_VO = 0;
	
	/**
	 * Definiert den Index für den Typ "Vorlesung Wahlpflicht"
	 */
	public static final int TYPE_VW = 1;
	
	/**
	 * Definiert den Index für den Typ "Praktikum Obligatorisch"
	 */
	public static final int TYPE_PO = 2;
	
	/**
	 * Definiert den Index für den Typ "Praktikum Wahlpflicht"
	 */
	public static final int TYPE_PW = 3;
	
	/**
	 * Definiert den Index für den Typ "Übung Obligatrisch"
	 */
	public static final int TYPE_UEO = 4;
	
	/**
	 * Definiert den Index für den Typ "Lerngruppen Event"
	 */
	public static final int TYPE_LT = 5;

	/**
	 * 
	 */
	public static final int TYPE_UNDEFINED = 6;

	public static final byte MONDAY = 0;
	
	public static final byte THUESDAY = 1;
	
	public static final byte WEDNESDAY = 2;
	
	public static final byte THURSDAY = 4;
	
	public static final byte FRYDAY = 5;
	
	public static final byte SATURDAY = 6;
	
	public static final byte SUNDAY = 7;
	
	/**
	 * contains the RecordId
	 */
	private int recordId;

	/**
	 * contains the interval in weeks in which the event takes place
	 */
	private byte intervall = 1;
	
	private byte day = MONDAY; 

	/**
	 * contains the Type of the Event
	 */
	private int type = TYPE_UNDEFINED;

	/**
	 * contains the name of the Event
	 */
	private String name = "";

	/**
	 * contains the place where the event should take place
	 */
	private String place = "";

	/**
	 * contains the Tutor of the Events
	 */
	private String tutor = "";

	/**
	 * contains the start time to which the event takes place. this time is an
	 * offset to dateStartOfEvent in milliseconds to represent an specific time
	 * of the day
	 */
	private int timeBeginOfEvent = 0;

	/**
	 * contains the end time to which the event takes place
	 * this time is an offset to dateStartOfEvent in milliseconds
	 */ 
	private int timeEndOfEvent = 0;

	/**
	 * contains the some extra Info of the Event
	 */
	private String infoText = "";

	public void deserialize(DataInputStream in) throws IOException {

		setRecordId(in.readInt());
		setDay(in.readByte());
		setTimeBeginOfEvent(in.readInt());
		setTimeEndOfEvent(in.readInt());
		setIntervall(in.readByte());
		setType(in.readInt());
		setInfoText(in.readUTF());
		setName(in.readUTF());
		setPlace(in.readUTF());
		setTutor(in.readUTF());

	}

	public byte getDay() {
		return day;
	}

	public String getInfoText() {
		return infoText;
	}

	public IRMSSerializeable getInstance() {
		return new Event();
	}

	public byte getIntervall() {
		return intervall;
	}

	public String getName() {
		return name;
	}

	public String getPlace() {
		return place;
	}

	public int getRecordId() {
		return recordId;
	}

	public int getTimeBeginOfEvent() {
		return timeBeginOfEvent;
	}

	public int getTimeEndOfEvent() {
		return timeEndOfEvent;
	}

	public String getTutor() {
		return tutor;
	}

	public int getType() {
		return type;
	}

	public void serialize(DataOutputStream out) throws IOException {

		out.writeInt(getRecordId());
		out.writeByte(getDay());
		out.writeInt(getTimeBeginOfEvent());
		out.writeInt(getTimeEndOfEvent());
		out.writeByte(getIntervall());
		out.writeInt(getType());
		out.writeUTF(getInfoText());
		out.writeUTF(getName() == null ? "" : getName());
		out.writeUTF(getPlace() == null ? "" : getPlace());
		out.writeUTF(getTutor() == null ? "" : getTutor());

	}

	public void setDay(byte day) {
		this.day = day;
	}

	public void setInfoText(String infoText) {
		this.infoText = infoText;
	}

	public void setIntervall(byte intervall) {
		this.intervall = intervall;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPlace(String place) {
		this.place = place;
	}

	public void setRecordId(int id) {
		recordId = id;
	}

	public void setTimeBeginOfEvent(int beginTimeOfEvent) {
		this.timeBeginOfEvent = beginTimeOfEvent;
	}

	public void setTimeEndOfEvent(int endTimeOfEvent) {
		this.timeEndOfEvent = endTimeOfEvent;
	}

	public void setTutor(String tutor) {
		this.tutor = tutor;
	}

	public void setType(int type) {
		this.type = type;
	}

}
